package com.b.sts.controller;

import com.b.sts.entity.LogEntity;
import com.b.sts.service.LogService;
import com.b.sts.util.ResultUtil;
import com.b.sts.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {

    @Resource
    private LogService logService;

    @GetMapping("/{id}")
    public ResultVO<LogEntity> getById(@PathVariable Long id) {
        return ResultUtil.success(logService.getById(id));
    }

    @GetMapping("/list")
    public ResultVO<List<LogEntity>> list(LogEntity entity) {
        List<LogEntity> data = logService.list(entity);
        return ResultUtil.success(data);
    }


    @PostMapping
    public ResultVO<Object> add(@RequestBody LogEntity logEntity) {
        boolean b = logService.add(logEntity);
        return ResultUtil.autoDo(b);
    }

    @DeleteMapping("/{id}")
    public ResultVO<Object> del(@PathVariable Long id) {
        return ResultUtil.autoDo(logService.removeById(id));
    }

    @PutMapping
    public ResultVO<Object> update(@RequestBody LogEntity logEntity) {
        return ResultUtil.autoDo(logService.updateById(logEntity));
    }
}
